package com.crm.config;

import com.crm.properties.AliOssProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.crm.utils.AliOssUtil;

@Configuration
@Slf4j
public class OssConfiguration {
    @ConditionalOnMissingBean //Bean不存在时，才会创建一个新的Bean实例，存在，就不创建，防止重复创建
    @Bean
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties) {
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());
    }
}
